<template>
    <div class="debris-list" v-loading="loading">
        <div class="input-box" v-if="userData">
            <span class="input-title" style="margin-left:0px;">昵称：</span>
            <span class="input-txt">{{ userData.nickName }}</span>
            <span class="input-title">ID：</span>
            <span class="input-txt">{{ userData.userId }}</span>
            <span class="input-title">性别：</span>
            <span class="input-txt" v-if="userData.gender === 1">男</span>
            <span class="input-txt" v-else-if="userData.gender === 2">女</span>
            <span class="input-txt" v-else>未知</span>
            <!-- 权限可编辑区 开始 -->
            <p style="display: inline;">
                <span class="input-title">权限：</span>
                <span class="input-txt" v-if="!editPos">{{ identity }}<i class="el-icon-edit"  v-if="!editPos" @click="editPos = true"></i></span>
                <el-select v-model="userData.identity" size="mini" v-else style="width: 100px;" @change="positionChange" placeholder="请选择">
                    <el-option v-for="(item, index) in identityList" :key="index" :label="item.label" :value="item.value"></el-option>
                </el-select>
                <i class="el-icon-success" v-if="editPos" @click="identitySave"></i>
                <i class="el-icon-error" v-if="editPos" @click="identityCancel"></i>
            </p>
            <!-- 权限可编辑区 结束 -->
            <div style="display: inline;">
                <span class="input-title">来源：</span>
                <p style="display: inline;" v-for="(item, index) in fromList" :key="index">
                    <span v-if="userData.channel === item.channel">{{ item.desc }}</span>
                </p>
                <span v-if="!userData.channel">-</span>
            </div>
            <span class="input-title">注册时间：</span>
            <span class="input-txt">{{ tableFormatDate(userData.createTime) }}</span>
        </div>
        <div class="table-box">
            <el-table :data="tableData" max-height="500" ref="table" border style="width: 100%">
                <el-table-column min-width="80" prop="exp" label="经验"></el-table-column>
                <el-table-column min-width="120" label="等级" prop="level"></el-table-column>
                <el-table-column min-width="80" label="星级" prop="score"></el-table-column>
                <el-table-column min-width="100" label="队长等级">
                    <template slot-scope="scope">
                        <span v-if="scope.row.captainLevel === 1">见习队长 </span>
                        <span v-if="scope.row.captainLevel === 2">进阶队长 </span>
                        <span v-if="scope.row.captainLevel === 3">铜牌队长 </span>
                        <span v-if="scope.row.captainLevel === 4">银牌队长 </span>
                        <span v-if="scope.row.captainLevel === 5">金牌队长 </span>
                        <span v-if="scope.row.captainLevel === 6">皇冠队长 </span>
                        <span v-if="!scope.row.captainLevel">-</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="负面积分">
                    <template slot-scope="scope">
                        <span>{{ scope.row.fuScore || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="80" label="粉丝">
                    <template slot-scope="scope">
                        <span>{{ scope.row.fansNum || '0' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="80" label="关注">
                    <template slot-scope="scope">
                        <span>{{ scope.row.watchNum || '0' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="互相关注" prop="">
                    <template slot-scope="scope">
                        <span>{{ scope.row.followEachOtherNum || '0' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="累计对局">
                    <template slot-scope="scope">
                        <span>{{ scope.row.gameCount || '0' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="单局补贴">
                    <template slot-scope="scope">
                        <span>{{ scope.row.oneGameIncome || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="累计收益" prop="income">
                    <template slot-scope="scope">
                        <p v-if="scope.row.income">{{ scope.row.income }}</p>
                        <p v-else>-</p>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="补贴开关">
                    <template slot-scope="scope">
                        <div v-if="scope.row.openReward === 1">开启</div>
                        <div v-else>关闭</div>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="今日处罚">
                    <template slot-scope="scope">
                        <div>{{ scope.row.todayPunishCount || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="170" label="解除禁赛时间">
                    <template slot-scope="scope">
                        <div v-if="scope.row.endTime">{{ tableFormatDate(scope.row.endTime) }}</div>
                        <div v-else>-</div>
                    </template>
                </el-table-column>
                <el-table-column label="总处罚">
                    <template slot-scope="scope">
                        <div>{{ scope.row.totalPunishCount || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="100" label="大神局胜率">
                    <template slot-scope="scope">
                        <div>{{ scope.row.kingPercent || 0 }}%</div>
                    </template>
                </el-table-column>
                <el-table-column label="好评率">
                    <template slot-scope="scope">
                        <div>{{ scope.row.goodCommentPercent || 0 }}%</div>
                    </template>
                </el-table-column>
                <el-table-column width="140" label="大神局被投诉次数">
                    <template slot-scope="scope">
                        <div>{{ scope.row.complaintCount || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="150" label="日均接单时长(分钟)">
                    <template slot-scope="scope">
                        <div>{{ scope.row.minuteCreateOrder || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="100" label="被拉黑次数">
                    <template slot-scope="scope">
                        <div>{{ scope.row.blockCount || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="170" label="成为队长时间">
                    <template slot-scope="scope">
                        <div v-if="scope.row.changeCaptainTime">{{ tableFormatDate(scope.row.changeCaptainTime) }}</div>
                        <div v-else>-</div>
                    </template>
                </el-table-column>
                <el-table-column width="120" label="大神局总局数">
                    <template slot-scope="scope">
                        <div>{{ scope.row.kingTotalStartGame || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="100" label="被考核次数">
                    <template slot-scope="scope">
                        <div>{{ scope.row.checkCount || 0 }}</div>
                    </template>
                </el-table-column>
                <el-table-column width="120" label="被取消大神次数">
                    <template slot-scope="scope">
                        <div>{{ scope.row.cancelKingCount || 0 }}</div>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'

export default {
    name: 'userTabel',
    props: {
        countParams: {
            type: Function,
            default: null
        }
    },
    data () {
        return {
            position: 0,
            identity: '',
            identityList: [
                {
                    label: '队员',
                    value: 0
                },
                {
                    label: '队长',
                    value: 4
                },
                {
                    label: '运营',
                    value: 5
                }
            ],
            userData: {},
            fromList: [],
            tableData: [],
            loading: false,
            editPos: false
        }
    },
    created () {
        this.getList(1, 10)
        this.getFromList()
    },
    methods: {
        // 获取列表
        async getList (pageNum, pageSize) {
            if (this.loading) return
            this.loading = true
            let params = {
                userId: this.$route.query.userId
            }

            let res = await this.$http.get('/team/getTeamUserInfoDetail', {
                params
            })
            if (res.code === '0') {
                this.tableData = [res.data]
                this.userData = res.data
                this.identityList.find(item => {
                    if (item.value === res.data.identity) {
                        this.identity = item.label
                        this.currentIdentity = item.label
                    }
                })
                let {
                    receiveCommentCount,
                    sendCommentCount,
                    historyConditionCount,
                    kingPercent
                } = res.data
                let countList = {
                    receiveCommentCount,
                    sendCommentCount,
                    historyConditionCount,
                    kingPercent
                }
                this.countParams(countList)
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        async getFromList () {
            let res = await this.$http.get('/apkManage/getChannel')
            if (res.code === '0') {
                this.fromList = res.data
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
        },
        // 查看用户详情
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        },
        positionChange (val) {
            this.currentIdentity = val
        },
        identitySave () {
            this.editPos = false
            this.$http.post('/team/updateIdentity', {
                userIdList: [this.$route.query.userId],
                type: this.currentIdentity
            }).then(res => {
                if (res.code === '0') {
                    this.identityList.find(item => {
                        if (item.value === this.currentIdentity) {
                            this.identity = item.label
                        }
                    })
                    this.$message({
                        type: 'success',
                        message: '权限修改成功'
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: '系统异常，请稍后再试'
                    })
                }
            })
        },
        identityCancel () {
            this.editPos = false
            this.userData.identity = this.identity
        },
        tableFormatDate (time) {
            return formatDate(time, 'YYYY-MM-DD HH:MM:SS')
        }
    }
}
</script>

<style lang="scss" scoped>
    .debris-list {
        .input-box {
            display: flex;
            align-items: center;
            min-height: 30px;
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin-left: 20px;
            }
            .input-txt {
                font-size: 12px;
                color: rgba($color: #000000, $alpha: 0.6);
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
            i {
                margin-left: 5px;
                font-size: 14px;
                color: #409EFF;
                cursor: pointer;
            }
        }

        .table-box {
            margin: 20px 0;
            .cover {
                width: 80px;
                height: 80px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
            .user-icon {
                width: 20px;
                height: 20px;
                border-radius: 50%;
                margin-right: 5px;
                vertical-align: top;
            }
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
        }
    }
</style>
